import {createReducer} from 'redux-act';
import u from 'updeep';
import {createAction2} from '../util';
import {bed, up, dataKey} from '../util/bed';
import * as ajax from '../util/ajax';
import * as http from '../util/http';
const name = 'medicalRecord';
const [
    getClassAndSeg,
    getSegTypeElements
] = [
    `${name}_getClassAndSeg`,
    `${name}_getSegTypeElements`
].map(createAction2);
export const actions = {
    getClassAndSeg: (q = {}) => bed(ajax.get(http.makeUrl(`/${name}/getclassandseg`, q)), getClassAndSeg),
    getSegTypeElements: (q = {}) => bed(ajax.get(http.makeUrl(`/${name}/getelementvalue`, q)), getSegTypeElements)
};
/**
 * NOTE:由于antd treesselect中需要id是字符串,获取和新建是转换保持一致
 */
export default createReducer({
    [getClassAndSeg]: (state, payload) => {
        let result = up(state, payload);
        const {data} = payload;
        if (data) {
            result = u({[dataKey]: data}, result);
        }
        return result;
    },
    [getSegTypeElements]: (state, payload) => {
        let result = up(state, payload);
        const {data} = payload;
        if (data) {
            result = u({[dataKey]: data}, result);
        }
        return result;
    }
}, {});
